using System.Collections;
using ArmyAnt.ProcessController;
using ArmyAnt.ViewUtil.Components;
using PlayMyLife.Events;
using UnityEngine;

namespace PlayMyLife.View.Components
{
    public class EventMgr : EventManager<DirectorEvent>, ICoroutineExecuter {
        public ICoroutineTask RunCoroutine(IEnumerator process) {
            return new CoroutineTask() { Target = process, coroutine = StartCoroutine(process) };
        }

        public IEnumerator CreateSecondsDelay(float seconds) {
            if(seconds > float.Epsilon) {
                yield return new WaitForSeconds(seconds);
            }
        }

        private class CoroutineTask : ICoroutineTask {
            public IEnumerator Target { get; set; }
            public object Current => Target.Current;
            public bool MoveNext() => Target.MoveNext();
            public void Reset() => Target.Reset();
            public Coroutine coroutine;
        }
    }

}
